#include <stdio.h>
#include <errno.h>
#include "config.h"
#include "link_socket.h"

zlog_category_t     *gZlog;

int initAppLog(const char* zlogConFile, char* cName)
{
    int ret = -1;
    ret = zlog_init(zlogConFile);
    if (ret){
        printf("FINE:[%s], FUNC:[%s], LINE:[%d] error:zlog init failed, zlogConFile:[%s], ret:[%d]\n", \
        __FILE__, __func__, __LINE__, zlogConFile, ret);
        return -1;
    }
	gZlog = zlog_get_category(cName);
	if (!gZlog) {
		printf("FINE:[%s], FUNC:[%s], LINE:[%d] error:get [%s] fail\n", \
        __FILE__, __func__, __LINE__, cName);
		zlog_fini();
		return -EFAULT;
	}
	zlog_debug(gZlog, "zlog init success");
    return 0;
}

int hostCmdExe(void *id, char *payload, int size,
                  int op1, int op2, int errcode, 
                  struct frame_list *frames)
{
  zlog_info(gZlog, "client cmd executed\n");
  return 0;
}

int devCmdExe(void *id, char *payload, int size,
                  int op1, int op2, int errcode, 
                  struct frame_list *frames)
{
  zlog_info(gZlog, "server cmd executed\n");
  return 0;
}

int main()
{
  int ret = -1;
  ret = initAppLog("test.cfg", "test");
  
  linkCtlInfo_t linkServerCtl = {
    .server.ipAddr  = "192.168.100.163",
    .server.port    = 8016,
    .linkCtlType    = ADD_LINK_CTL,
  };
  ret |= tcpDevConnectCtl(linkServerCtl, devCmdExe);

  ret |= tcpServerInit(hostCmdExe);
  return 0;
}
